/**
 * 
 */
$(document).ready(function(){
	var userId = $("#hidden_userId").val();
	getUser(userId);
	initTree();
	getRoles(userId);
});
var treeNodes; 
function initTree() {
	var companyId = $("#property_company_name").attr("data-id");
	$.ajax({  
        async : false,  
        cache:false,  
        type: 'POST', 
        data: {comingParams:JSON.stringify({"companyId" :companyId,"userId":$("#hidden_userId").val()})},
        dataType : "json",  
        url: "userAction!getOrgs.action",//请求的action路径  
        error: function () {//请求失败处理函数  
            alert('请求失败');  
        },  
        success:function(data){ //请求成功后处理函数。    
        	data = eval("(" + data + ")");
            treeNodes = data.data;   //把后台封装好的简单Json格式赋给treeNodes  
        }  
    });
	var zTreeDemo = $.fn.zTree.init($("#cityTree"),setting, treeNodes);
	var nodes = zTreeDemo.getNodes();
	/*disabled = true, inheritParent = true, inheritChildren = false;
	for (var i = 0; i<nodes.length; i++) {
		zTreeDemo.setChkDisabled(nodes[i], disabled, inheritParent, inheritChildren);
	}*/
}

var setting = {
	check: {
		enable: true,
		chkStyle: "checkbox",
		chkboxType: {"Y":"","N":""}
	},
	data: {
		simpleData: {
			enable: true
		}
	}
};
function getRoles(userId){
	$.ajax({  
        async : false,  
        cache:false,  
        type: 'POST', 
        data: {"comingParams" : JSON.stringify({"userId" :userId,"qryType":"u"})},
        dataType : "json",  
        url: "userAction!getRoles.action",//请求的action路径  
        error: function () {//请求失败处理函数  
            alert('请求失败');  
        },  
        success:function(data){ //请求成功后处理函数。    
        	data = eval("("+data+")");
	    	if (data.result == "true") {
	    		$(data.data).each(function(ix, ite) {
	    			var roleLabel = '<label class="checkbox inline"><input type="checkbox" value="'
	    				+ite.id+'" name="check" onclick="return false;" ';
	    			if (ite.checked==true){ 
	    				roleLabel =roleLabel+'checked="checked"';
	    			}
	    			roleLabel = roleLabel + '/>'+ite.name+'</label>';
	    			$("#roles").append(roleLabel);
	    		});
			}else {
				alert("查询失败"+data.msg);
			}
        }  
    });
}
function getUser(userId){
	/*$.post(
		    "userAction!getUser.action",
		    {"comingParams" : JSON.stringify({"userId" :userId})},
		    function(data) {
		    	data = eval("("+data+")");
		    	if (data.result == "true") {
		    		des(data);
				}else {
					alert("查询失败"+data.msg);
				}
		    	
		    }
		);*/
	
	$.ajax({  
        async : false,  
        cache:false,  
        type: 'POST', 
        data: {"comingParams" : JSON.stringify({"userId" :userId})},
        dataType : "json",  
        url: "userAction!getUser.action",//请求的action路径  
        error: function () {//请求失败处理函数  
            alert('请求失败');  
        },  
        success:function(data){ //请求成功后处理函数。    
        	data = eval("("+data+")");
	    	if (data.result == "true") {
	    		des(data);
			}else {
				alert("查询失败"+data.msg);
			}
        }  
    });
}

function des(data){
	var dataList = data.data;
	if (dataList != null){
		var user = dataList[0];
		$("#user_account").text(user.account);
		var partyInfo = user.partyInfo;
		if (!StrUtil.isEmpty(partyInfo)){
			$("#user_name").text(partyInfo.partyName);
		}
		var address = partyInfo.address;
		if (address != null){
			var area = address.area;
			var upArea1 = area.upArea;
			var upArea2 = upArea1.upArea;
			var detailAdd =StrUtil.strnull(address.detailAddress);
			if (upArea1.areaType=="10"){
				detailAdd = upArea1.areaName+area.areaName+StrUtil.strnull(address.detailAddress);
			}else{
				detailAdd = upArea2.areaName+upArea1.areaName+area.areaName+StrUtil.strnull(address.detailAddress);
			}
			$("#address").text(detailAdd);
		}
		
		$("#user_status").text(user.statusName);
		if ("10" == user.userType){
			$("#user_type").text("平台用户");
		}else if ("11" == user.userType){
			$("#user_type").text("物业用户");
		}else{
			$("#user_type").text("未知");
		}
		$("#user_cert_type").text(partyInfo.certTypeName);
		$("#user_cert_nbr").text(partyInfo.certNbr);
		
		if (!StrUtil.isEmpty(user.company)){
			$("#property_company_name").text(user.company.companyName);
			$("#property_company_name").attr("data-id",user.company.companyId)
		}
		if (!StrUtil.isEmpty(user.community)){
			$("#community_name").text(user.community.communityName);
		}
		
	}
}